﻿using KWT.DRG_DIP.DB;
using KWT.DRG_DIP.DO.System;
using KWT.DRG_DIP.PO.Basic;

namespace KWT.DRG_DIP.API.Infrastructure
{
    public interface IMySqlConnectionResolver
    {
        string GetConnection();

    }

    public class HttpHeaderMySqlConnectionResolver : IMySqlConnectionResolver
    {
        private readonly TenantInfo tenantInfo;
        private readonly IConfiguration configuration;
        public MainDapperHelper dapper { get; set; }
        public HttpHeaderMySqlConnectionResolver(TenantInfo tenantInfo, IConfiguration configuration)
        {
            this.tenantInfo = tenantInfo;
            this.configuration = configuration;
        }
        public string GetConnection()
        {
            //var connectionString = configuration.GetConnectionString(tenantInfo.Name);
            //if (string.IsNullOrEmpty(connectionString))
            //{
            //    throw new Exception("获得链接字符串错误！");
            //}
            var tenant = dapper.SelectSingle<Sys_Tenant>("select * from sys_tenant where tenantid=@id", new { id = tenantInfo.Name });
            return tenant.ConnStr;
        }
    }
}
